package org.javaboy.vhr.controller.system.basic;

import com.sun.org.apache.bcel.internal.generic.NEW;
import org.javaboy.vhr.model.JobLevel;
import org.javaboy.vhr.model.Menu;
import org.javaboy.vhr.model.RespBean;
import org.javaboy.vhr.model.Role;
import org.javaboy.vhr.service.MenuService;
import org.javaboy.vhr.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Willie Chen
 * @Description
 * @Date 2019/12/22
 * @Param $param
 **/
@RestController
@RequestMapping("/system/basic/permiss")
public class PermissController {

    @Autowired
    RoleService roleService;
    @Autowired
    MenuService menuService;


    @GetMapping("/")
    public List<Role> getALLRoles() {

        return roleService.getALLRoles();
    }

    @GetMapping("/menu")
    public List<Menu> getAllMenus() {

        return menuService.getAllMenus();
    }


    @GetMapping("/mids/{rid}")
    public List<Integer> getMidsByRid(@PathVariable Integer rid) {

        return menuService.getMidsByRid(rid);
    }

    @PutMapping("/")
    public RespBean updateMenuRole(@RequestParam Integer rid, Integer[] mids) {

        if (menuService.updateMenuRole(rid, mids)  ) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @PostMapping("/role")
    public  RespBean addRole(@RequestBody Role role){
     if(roleService.addRole(role) == 1){

         return  RespBean.ok("添加成功");
     }

        return RespBean.error("更新失败!");
    }

    @DeleteMapping("/role/{rid}")
    public  RespBean deleteRoleById(@PathVariable Integer  rid){
         if(roleService.deleteRoleById(rid) == 1){

             return  RespBean.ok("删除成功");
         }

        return RespBean.error("删除失败!");
    }

}
